<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of EmailIdentity
 *
 * @author dung3625@gmail.com
 * @date 01/03/2014
 */
class EmailIdentity extends CBaseUserIdentity{
    
                    public $email;
	
	public function __construct($email)
	{
		$this->email=$email;
	}

	public function getId()
	{
		return $this->email;
	}

	public function getName()
	{
		return $this->email;
	}

    public function authenticate() {
                    try{
                        $connection=Yii::app()->db;   // assuming you have configured a "db" connection
                        $query="SELECT os_users.email FROM os_users  WHERE os_users.email='{$this->email}' limit 1 ";
                        $command=$connection->createCommand($query);
                        $dataReader=$command->query();
                        $rows_user = array();
                        while(($row=$dataReader->read())!==false) {
                            $rows_user[]=$row;
                        }      
                        if(empty($rows_user)) 
                             $this->errorCode="Email is blank.";
                        elseif($rows_user[0]["email"]!==$this->email)
                                $this->errorCode="Email is blank.";
                        else
                                $this->errorCode=NULL;
                        return !$this->errorCode;
                    }catch(Exception $e){}     
                    }
}

?>
